package com.markedquilt.solution;
/*
 * PackageName: com.markedquilt.solution
 * ClassName:   MergeTwoArray
 * Author:   zhang
 * Date:     Created in 2020/10/23
 * Description:
 * History:
 * <author>        <time>             <version>          <desc>
 * 作者姓名         修改时间            版本号              描述
 * zhang           2020/10/23      1.0
 */

import java.util.Arrays;

/**
 * Title:
 * Project: LeetcodeProblem
 *
 * @author ZhangKe
 * Created on 2020/10/23
 */
public class num88MergeTwoArray {
    
    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        if (nums2.length==0){
            return;
        }
        if (m==0){
            for (int i = 0; i < n; i++) {
                nums1[i] = nums2[i];
            }
            return;
        }
        int index1=m-1,index2 = n-1;
        for (int i = m+n-1; i >=0 && index1>=0 && index2>=0; i--) {
            if (nums1[index1] > nums2[index2]){
                nums1[i] = nums1[index1];
                nums1[index1--] =Integer.MIN_VALUE;
            }else if (nums1[index1] <= nums2[index2]){
                nums1[i] = nums2[index2--];
            }
        }
    }

    public static void main(String[] args) {
        int[] a = {2,0};
        int[] b = {1};
        merge(a,1,b,1);
        for (int i : a) {
            System.out.println(i+"  ");
        }
    }
}
